x = input()
int_x = int(x)
prime = []
if len(x)== 4:
  list = [x[0],x[0:2],x[0:3],x[0:4],x[1],x[1:3],x[1:4],x[2],x[2:4],x[3]]
  for b in range(0,10):
    count = 0
    for i in range(1,int(list[b])+1):
      if int(list[b]) % i == 0:
        count+=1
    if count ==2:
      prime.append(int(list[b]))
  if any(prime):
    print(max(prime))
  else:
    print(0)
else:
  print(0)
